package com.hrc.rpc.config;

import com.hrc.rpc.annotation.PropertiesField;
import com.hrc.rpc.annotation.PropertiesPrefix;
import com.hrc.rpc.common.constants.RegistryRules;
import com.hrc.rpc.common.constants.SerializationRules;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;

import java.util.HashMap;
import java.util.Map;

@PropertiesPrefix("rpc")
@ConfigurationProperties("rpc")
@Data
public class RpcProperties {


    static RpcProperties rpcProperties;
    /**
     * netty 端口
     */
    @PropertiesField
    private Integer port;
    /**
     * 注册中心地址
     */
    @PropertiesField
    private String registerAddr;
    /**
     * 注册中心类型
     */
    @PropertiesField
    private String registerType = RegistryRules.ZOOKEEPER;
    /**
     * 注册中心密码
     */
    @PropertiesField
    private String registerPsw;
    /**
     * 序列化
     */
    @PropertiesField
    private String serialization = SerializationRules.JSON;
    /**
     * 服务端额外配置数据
     */
    @PropertiesField("service")
    private Map<String, Object> serviceAttachments = new HashMap<>();
    /**
     * 客户端额外配置数据
     */
    @PropertiesField("client")
    private Map<String, Object> clientAttachments = new HashMap<>();

    private RpcProperties() {
    }

    public static RpcProperties getInstance() {
        if (rpcProperties == null) {
            rpcProperties = new RpcProperties();
        }
        return rpcProperties;
    }

}
